using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using ININ;
using IUPUI.StellarResults;

namespace IUPUI.StellarResults.UnitTest
{
	/// <summary>
	/// Provides tests for the <see cref="AstronomicalCalculations"/> class.
	/// </summary>
	[TestFixture]
	public class AstronomicalCalculationsTest
	{
		/// <summary>
		/// This method is used to construct the test environment prior to running the tests.
		/// </summary>
		[TestFixtureSetUp]
		public void Init()
		{
		}

		/// <summary>
		/// This method is used to restore the environment after the tests are completed.
		/// </summary>
		[TestFixtureTearDown]
		public void Dispose()
		{
			System.Console.WriteLine();
			System.Console.WriteLine();
		}

		[Test]
		public void AltAzFixed()
		{
			ObservationType ot;
			Observatory o;
			AstronomicalObject a;
			Altazimuth obj_altaz;
			o = new Observatory();
			a = new AstronomicalObject();
			ot = ObservationType.RotatingEarth;

			//test one
			o.Coordinates.Longitude = -85.99;
			o.Coordinates.Latitude = 39.92;
			a.Position.Declination = -30;
			a.Position.RightAscension = 150;
			a.PositionType = PositionType.Fixed;
            obj_altaz = AstronomicalCalculations.ComputeAzimuthAngle(a, o, ot, new DateTime(2007, 11, 15, 21, 30, 0, System.DateTimeKind.Local).ToUniversalTime(), DateTime.Now);
			Assert.IsTrue(Math.Abs(obj_altaz.Altitude + 58.88) < 1);     //-58.88
			Assert.IsTrue(Math.Abs(obj_altaz.Azimuth - 82.85) < 1);   //82.85

			////test two
			o.Coordinates.Longitude = -85.99;
			o.Coordinates.Latitude = 39.92;
			a.Position.Declination = .25;
			a.Position.RightAscension = 345;
			a.PositionType = PositionType.Fixed;
            obj_altaz = AstronomicalCalculations.ComputeAzimuthAngle(a, o, ot, new DateTime(2004, 8, 2, 5, 30, 0, System.DateTimeKind.Local).ToUniversalTime(), DateTime.Now);
			Assert.IsTrue(Math.Abs(obj_altaz.Altitude - 45.21) < 1);     //45.21
			Assert.IsTrue(Math.Abs(obj_altaz.Azimuth - 213.42) < 1);   //213.42
			////test three
			o.Coordinates.Longitude = -85.99;
			o.Coordinates.Latitude = 39.92;
			a.Position.Declination = 80.25;
			a.Position.RightAscension = 45;
			a.PositionType = PositionType.Fixed;
			obj_altaz = AstronomicalCalculations.ComputeAzimuthAngle(a, o, ot, new DateTime(2001, 11, 29, 5, 30, 0, System.DateTimeKind.Local).ToUniversalTime(),DateTime.Now );
			Assert.IsTrue(Math.Abs(obj_altaz.Altitude - 38.41) < 1);     //38.41
			Assert.IsTrue(Math.Abs(obj_altaz.Azimuth - 347.56) < 1);   //347.56
		}

		[Test]
		public void ALtAzOrbit()
		{
			ObservationType ot;
			Observatory o;
			AstronomicalObject a;
			Altazimuth obj_altaz;
			o = new Observatory();
			a = new AstronomicalObject();
			ot = ObservationType.RotatingEarth;
			//test one
			o.Coordinates.Longitude = -85.99;
			o.Coordinates.Latitude = 39.92;
			a.Position.Declination = 80;
			a.Position.RightAscension = 225;
			a.Speed = 15;
			a.PositionType = PositionType.Orbit;
            obj_altaz = AstronomicalCalculations.ComputeAzimuthAngle(a, o, ot, new DateTime(2000, 1, 2, 0, 0, 0, System.DateTimeKind.Utc), DateTime.Now);
			Assert.IsTrue(Math.Abs(obj_altaz.Altitude - 31.1) < 1);     //31.1
			Assert.IsTrue(Math.Abs(obj_altaz.Azimuth - 354.17) < 1);   //354.17
			//test two
			o.Coordinates.Longitude = -85.99;
			o.Coordinates.Latitude = 39.92;
			a.Position.Declination = -80;
			a.Position.RightAscension = 15;
			a.Speed = 60;
			a.PositionType = PositionType.Orbit;
            obj_altaz = AstronomicalCalculations.ComputeAzimuthAngle(a, o, ot, new DateTime(2000, 1, 2, 0, 0, 0, System.DateTimeKind.Utc), DateTime.Now);
			Assert.IsTrue(Math.Abs(obj_altaz.Altitude + 29.91) < 1);     //-29.91
			Assert.IsTrue(Math.Abs(obj_altaz.Azimuth - 179.99) < 1);   //179.99
			//test three
			o.Coordinates.Longitude = -85.99;
			o.Coordinates.Latitude = 39.92;
			a.Position.Declination = 0;
			a.Position.RightAscension = 0;
			a.Speed = 90;
			a.PositionType = PositionType.Orbit;
            obj_altaz = AstronomicalCalculations.ComputeAzimuthAngle(a, o, ot, new DateTime(2000, 1, 2, 0, 0, 0, System.DateTimeKind.Utc), DateTime.Now);
			Assert.IsTrue(Math.Abs(obj_altaz.Altitude - 47.81) < 1);     //47.81
			Assert.IsTrue(Math.Abs(obj_altaz.Azimuth - 202) < 1);   //202.62
		}

	}
}
